﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Log;
using mepostras.BO.Util;
using mepostras.DAL;

namespace mepostras.BO
{
    public class MessageConfigBo : IMessageConfigBo
    {
        public string GetMessageEnglish(string key)
        {
            return GetMessage(key, BoConfig.Language.English.ToLower());
        }

        public string GetMessageVietnamese(string key)
        {
            return GetMessage(key, BoConfig.Language.Vietnamese.ToLower());
        }

        public string GetMessage(string key, string language)
        {
            string result = string.Empty;
            try
            {
                var messageConfig = DataRepository.MessageConfigProvider.GetByKeyCodeLanguage(key, language.ToLower());
                result = messageConfig != null ? messageConfig.Value : string.Empty;

                if (messageConfig == null || string.IsNullOrEmpty(messageConfig.Value))
                {
                    SingletonLogger.Instance.Debug(String.Format("GetMessageEnglish-------Message Code {0} chưa có trong db", key));
                }
            }
            catch (Exception ex)
            {
                SingletonLogger.Instance.Error("GetMessageEnglish-------", ex);
            }
            return result;
        }
    }
}
